/*
 * sp003.cpp
 *
 *  Created on: 2012-11-15
 *      Author: feng
 */

#include "sample.h"

CSp003::CSp003(unsigned int w,unsigned int h):CSample(w,h) {
	m_fEarthAngle = 0.0f;
	m_fMoonAngle = 0.0f;
}

void CSp003::InitOpenGL() {
	CSample::InitOpenGL();
}

Uint32 CSp003::MyTimer(Uint32 interal,void *param) {
	m_fEarthAngle += 1.0f;
	if (m_fEarthAngle >= 360.0f)
		m_fEarthAngle = 0.0f;
	m_fMoonAngle += 5.0f;
	if (m_fMoonAngle >= 360.0f)
		m_fMoonAngle = 0.0f;
	return interal;
}

void CSp003::RenderOnce() {
	glEnable(GL_CULL_FACE);
	glEnable(GL_DEPTH_TEST);
	glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);
//	glPolygonMode(GL_BACK,GL_FILL);

	this->MyXYZ();

	glColor3ub(255,0,0);
	MySphere(30.0f,20,20);

	glPushMatrix();
	glColor3ub(255,255,0);
	glRotatef(m_fEarthAngle,0.0f,1.0f,0.0f);
	glTranslatef(120.0f,0.0f,0.0f);
	MySphere(20.0f,20,20);

	glColor3ub(255,255,255);
	glRotatef(45.0f,1.0f,0.0f,0.0f);
	glRotatef(m_fMoonAngle,0.0f,1.0f,0.0f);
	glTranslatef(50.0f,0.0f,0.0f);
	MySphere(10.0f,20,20);
	glPopMatrix();

}


void CSp003::OnEventWndResize(int w, int h) {
	MyPrint("sp003 wnd resize %d,%d",w,h);
	m_ScreenW = w;
	m_ScreenH = h;
	if (h == 0)
		h = 1;
	glViewport(0,0,w,h);

	GLdouble dRatio = (GLdouble)w/(GLdouble)h;
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(60.0,dRatio,1.0,800.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glTranslatef(0.0f,0.0f,-300.0f);
//	this->MyXYZ();
}

